<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
	  xmlns:jsp="http://java.sun.com/JSP/Page"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:a4j="http://richfaces.org/a4j"
	  xmlns:rich="http://richfaces.org/rich"
	  xmlns:validators="validators"
	  xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	  xmlns:p="http://primefaces.prime.com.tr/ui">
	<ui:composition template="/templates/main.xhtml">
		<ui:param name="bean" value="#{projetoBean}" />
		<ui:define name="body">
			<a4j:keepAlive beanName="projetoServiceImpl"/>
			<a4j:keepAlive beanName="projetoBean"/>		
			<a4j:form ajaxSubmit="true" id="papelForm" >
				<h:panelGroup layout="block" id="listPanel" rendered="#{projetoServiceImpl.projetoBean.listState}"
					binding="#{projetoServiceImpl.panelGroup}">
					<div align="center">
						<rich:extendedDataTable value="#{projetoServiceImpl.projetosDataModel}" var="projeto"
								width="700px" align="center" height="347px" id="projetos" 
								selection="#{projetoServiceImpl.projetoBean.selecaoProjeto}"
								selectionMode="single"
								onkeypress="if (event.keyCode == 13) {document.getElementById('recursos:nomefsp').blur(); document.getElementById('recursos:habilitadofsp').blur(); return false;} else {return true;}">
	        					
						 	<rich:column sortBy="#{projeto.nome}" style="text-align:left;" width="99%">
						 		<f:facet name="header">
									<h:outputText value="#{labels['papel.nome']}" />
								</f:facet>
								<h:outputText value="#{projeto.nome}"/>
							</rich:column>
						</rich:extendedDataTable>
					</div>
					
					<br />
					
					<a4j:commandButton action="#{projetoServiceImpl.prepareCreate}"
						 value="   #{labels['novo']}   " style="margin-left:68px;" id="btnNovo"/>
					<rich:spacer width="7" id="spacer1"/>
				    <a4j:commandButton action="#{projetoServiceImpl.showDetails}"
						 value="   #{labels['detalhar']}   " id="btnDetalhe"/>
					<rich:spacer width="7" id="spacer2"/>
				    <a4j:commandButton action="#{projetoServiceImpl.prepareUpdate}"
						 value="   #{labels['alterar']}   " id="btnUpdate"/>
				</h:panelGroup>
				
				<rich:tabPanel switchType="ajax" rendered="#{not projetoServiceImpl.projetoBean.listState}"
					valueChangeListener="#{projetoServiceImpl.mudarAba}" id="tabPanel">
			        <rich:tab label="#{labels['projeto.dadosGerais']}" id="tabGeral">
						<h:panelGrid columns="2" id="panelDadosGerais">
							<h:outputLabel value="#{labels['projeto.nome']}:" for="nome" id="labelNome"/>
							<h:inputText id="nome" value="#{projetoServiceImpl.projetoBean.nome}" 
								rendered="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}"
								maxlength="100" size="80"/>
							<h:outputText value="#{projetoServiceImpl.projetoBean.nome}" 
								rendered="#{projetoServiceImpl.projetoBean.detailState}" id="outputNome"/>
							
							<h:outputLabel value="#{labels['projeto.descricao']}:" for="descricao" id="labelDescricao"/>
							<rich:editor id="descricao" width="450" height="250" 
								theme="advanced" value="#{projetoServiceImpl.projetoBean.descricao}"
								rendered="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}">
								<f:param name="theme_advanced_buttons1" value="bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect"/>
								<f:param name="theme_advanced_buttons2" value="cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,|,forecolor,backcolor"/>
								<f:param name="theme_advanced_buttons3" value=""/>
								<f:param name="theme_advanced_buttons4" value=""/>
						        <f:param name="theme_advanced_toolbar_location" value="top"/>                               
         						<f:param name="theme_advanced_toolbar_align" value="left"/>
							</rich:editor>
							<h:outputText value="#{projetoServiceImpl.projetoBean.descricao}" 
								rendered="#{projetoServiceImpl.projetoBean.detailState}" escape="false" id="outputDescricao"/>
							
							<h:outputLabel value="#{labels['projeto.dataInicioPrevista']}:" for="dataInicioPrevista" id="labelDataInicioPrevista"/>
							<rich:calendar id="dataInicioPrevista" datePattern="dd/MM/yyyy" 
								value="#{projetoServiceImpl.projetoBean.dataInicioPrevista}" size="50"
								rendered="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}" />
							<h:outputText value="#{projetoServiceImpl.projetoBean.dataInicioPrevista}"
								rendered="#{projetoServiceImpl.projetoBean.detailState}" id="outputDataInicioPrevista">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputText>
							
							<h:outputLabel value="#{labels['projeto.dataFimPrevista']}:" for="dataFimPrevista" id="labelDataFimPrevista"/>
							<rich:calendar id="dataFimPrevista" datePattern="dd/MM/yyyy" 
								value="#{projetoServiceImpl.projetoBean.dataFimPrevista}" size="50"
								rendered="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}"/>
							<h:outputText value="#{projetoServiceImpl.projetoBean.dataFimPrevista}"
								rendered="#{projetoServiceImpl.projetoBean.detailState}" id="outputDataFimPrevista">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputText>
						</h:panelGrid>
						
						<br />
			        </rich:tab>
			        <rich:tab label="#{labels['projeto.observadores']}" id="tabObservadores">
			        	<h:panelGroup rendered="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}"
			        		id="panelPossiveisObservadores">
				        	<h:outputFormat value="#{labels['projeto.selecione']}" styleClass="pageMessage" id="message1">
				        		<f:param value="#{fn:toLowerCase(labels['projeto.observadores'])}"/>
				        	</h:outputFormat>
				        	
				        	<br />
				        	<br />
				        	
					        <rich:extendedDataTable id="possiveisObservadores" var="item"
								value="#{projetoServiceImpl.projetoBean.possiveisObservadores}"
								selectionMode="multiple" height="200px" style="cursor: pointer;"
								selection="#{projetoServiceImpl.projetoBean.selecaoObservadores}">
								
								<rich:column width="100%" label="Nome" sortable="true" sortBy="#{item.nome}" id="nomeObservadoresPossiveis">
									<f:facet name="header">
										Nome
									</f:facet>
									<h:outputText value="#{item.nome} #{item.sobrenome}"></h:outputText>	
								</rich:column>
				            </rich:extendedDataTable>
							
							<br />

						<a4j:commandButton
							action="#{projetoServiceImpl.selecionarObservadores}"
							value="#{labels['selecionar']}" reRender="observadores" id="btnSelecionar1"/>

						<br />
							<br />
							<br />
							
							<h:panelGroup rendered="#{not empty projetoServiceImpl.projetoBean.observadores}" id="panel1">
								<h:outputText value="Observadores Selecionados" styleClass="pageMessage" id="message6"/>
				        	
					        	<br />
					        	<br />
							</h:panelGroup>
						
				        </h:panelGroup>
				        	
							<rich:extendedDataTable id="observadoresSelecionados" var="item"
								value="#{projetoServiceImpl.projetoBean.observadores}"
								rendered="#{not empty projetoServiceImpl.projetoBean.observadores}"
								selectionMode="none" height="200px">
								
								<rich:column width="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState ? '90%' : '100%'}" sortable="true" sortBy="#{item.nome}" label="Nome">
									<f:facet name="header">
										Nome
									</f:facet>
									<h:outputText value="#{item.nome} #{item.sobrenome}"></h:outputText>	
								</rich:column>
								
								<rich:column style="text-align: center;" label="Excluir" 
									width="10%" rendered="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}">
									<f:facet name="header">
										Excluir											
									</f:facet>
									<h:graphicImage value="/img/disabled.png" style="cursor: pointer;">
										<a4j:support action="#{projetoServiceImpl.excluirObservador}"
											event="onclick" immediate="true">
											<f:setPropertyActionListener value="#{item}" target="#{projetoServiceImpl.projetoBean.recursoTemp}" />
										</a4j:support>
									</h:graphicImage>
								</rich:column>
				            </rich:extendedDataTable>
				            
				            <h:outputFormat value="#{labels['projeto.nenhumSelecionado']}" 
				            	rendered="#{empty projetoServiceImpl.projetoBean.observadores}" id="message2">
				            	<f:param value="#{fn:toLowerCase(labels['projeto.observador'])}"/>
				            </h:outputFormat>
			        </rich:tab>
			        
			        <rich:tab label="#{labels['projeto.gerentes']}" id="tabGerentes">
			        	<h:panelGroup rendered="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}"
			        		id="panelPossiveisGerentes">
				        	<h:outputFormat value="#{labels['projeto.selecione']}" styleClass="pageMessage" id="message3">
				        		<f:param value="#{fn:toLowerCase(labels['projeto.gerentes'])}"/>
				        	</h:outputFormat>
				        	
				        	<br />
				        	<br />
				        	
					        <rich:extendedDataTable id="possiveisGerentes" var="item"
								value="#{projetoServiceImpl.projetoBean.possiveisGerentes}"
								selectionMode="multiple" height="200px" style="cursor: pointer;"
								selection="#{projetoServiceImpl.projetoBean.selecaoGerentes}">
								
								<rich:column width="100%" label="Nome" sortable="true" sortBy="#{item.nome}" id="nomeGerentesPossiveis">
									<f:facet name="header">
										Nome
									</f:facet>
									<h:outputText value="#{item.nome} #{item.sobrenome}"></h:outputText>	
								</rich:column>
				            </rich:extendedDataTable>
							
							<br />
							
							<a4j:commandButton action="#{projetoServiceImpl.selecionarGerentes}" 
								value="#{labels['selecionar']}" id="btnSelecionar2"/>
							
							<br />
							<br />
							<br />
							
							<h:panelGroup rendered="#{not empty projetoServiceImpl.projetoBean.gerentes}" id="panel2">
								<h:outputText value="Gerentes Selecionados" styleClass="pageMessage" id="message7"/>
				        	
					        	<br />
					        	<br />
							</h:panelGroup>
						</h:panelGroup>
						
							<rich:extendedDataTable id="gerentesSelecionados" var="item"
								value="#{projetoServiceImpl.projetoBean.gerentes}"
								rendered="#{not empty projetoServiceImpl.projetoBean.gerentes}"
								selectionMode="none" height="200px">
								
								<rich:column width="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState ? '90%' : '100%'}" sortable="true" sortBy="#{item.nome}" label="Nome">
									<f:facet name="header">
										Nome
									</f:facet>
									<h:outputText value="#{item.nome} #{item.sobrenome}"></h:outputText>	
								</rich:column>
								
								<rich:column style="text-align: center;" label="Excluir" width="10%"
									rendered="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}">
									<f:facet name="header">
										Excluir											
									</f:facet>
									<h:graphicImage value="/img/disabled.png" style="cursor: pointer;">
										<a4j:support action="#{projetoServiceImpl.excluirGerente}"
											event="onclick" immediate="true">
											<f:setPropertyActionListener value="#{item}" target="#{projetoServiceImpl.projetoBean.recursoTemp}" />
										</a4j:support>
									</h:graphicImage>
								</rich:column>
				            </rich:extendedDataTable>
				            
				            <h:outputFormat value="#{labels['projeto.nenhumSelecionado']}" 
				            	rendered="#{empty projetoServiceImpl.projetoBean.gerentes}" id="message4">
				            	<f:param value="#{fn:toLowerCase(labels['projeto.gerente'])}"/>
				            </h:outputFormat>
			        </rich:tab>
			        
			        <rich:tab label="#{labels['projeto.recursos']}" id="tabRecursos">
			        	<h:panelGroup rendered="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}"
			        		id="panelPossiveisRecursos">
				        	<h:outputFormat value="#{labels['projeto.selecione']}" styleClass="pageMessage" id="message5">
				        		<f:param value="#{fn:toLowerCase(labels['projeto.recursos'])}"/>
				        	</h:outputFormat>
				        	
				        	<br />
				        	<br />
				        	
					        <rich:extendedDataTable id="possiveisRecursos" var="item"
								value="#{projetoServiceImpl.projetoBean.possiveisRecursos}"
								selectionMode="multiple" height="200px" style="cursor: pointer;"
								selection="#{projetoServiceImpl.projetoBean.selecaoRecursos}"
								rowKeyVar="index">
								
								<rich:column width="60%" label="Nome" sortable="true" sortBy="#{item.nome}">
									<f:facet name="header">
										Nome
									</f:facet>
									<h:outputText value="#{item.nome} #{item.sobrenome}" />	
								</rich:column>
								<rich:column width="40%" label="Papel">
									<f:facet name="header">
										Papel
									</f:facet>
									<rich:comboBox defaultLabel="Selecione um papel" value="#{item.papelProjeto}">
										<f:selectItems value="#{projetoServiceImpl.papeis}" />
									</rich:comboBox>
								</rich:column>
				            </rich:extendedDataTable>
							
							<br />
							
							<a4j:commandButton action="#{projetoServiceImpl.selecionarRecursos}" 
								value="#{labels['selecionar']}" id="btnSelecionar3"/>
							
							<br />
							<br />
							<br />
							
							<h:panelGroup rendered="#{not empty projetoServiceImpl.projetoBean.recursos}" id="panel3">
								<h:outputText value="Recursos Selecionados" styleClass="pageMessage" id="message8"/>
				        	
					        	<br />
					        	<br />
							</h:panelGroup>
						</h:panelGroup>
						
							<rich:extendedDataTable id="recursosSelecionados" var="item"
								value="#{projetoServiceImpl.projetoBean.recursos}"
								rendered="#{not empty projetoServiceImpl.projetoBean.recursos}"
								selectionMode="none" height="200px">
								
								<rich:column width="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState ? '59%' : '69%'}" sortable="true" sortBy="#{item.nome}" label="Nome">
									<f:facet name="header">
										Nome
									</f:facet>
									<h:outputText value="#{item.recursoProjetoPK.recurso.nome} #{item.recursoProjetoPK.recurso.sobrenome}"></h:outputText>	
								</rich:column>
								
								<rich:column width="31%" sortable="true" sortBy="#{item.nome}" label="Nome">
									<f:facet name="header">
										Papel
									</f:facet>
									<h:outputText value="#{item.papel.nome}"></h:outputText>	
								</rich:column>
								
								<rich:column style="text-align: center;" label="Excluir" width="10%"
									rendered="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}">
									<f:facet name="header">
										Excluir											
									</f:facet>
									<h:graphicImage value="/img/disabled.png" style="cursor: pointer;">
										<a4j:support action="#{projetoServiceImpl.excluirRecurso}"
											event="onclick" immediate="true">
											<f:setPropertyActionListener value="#{item}" target="#{projetoServiceImpl.projetoBean.recursoProjetoTemp}" />
										</a4j:support>
									</h:graphicImage>
								</rich:column>
				            </rich:extendedDataTable>
				            
				            <h:outputFormat value="#{labels['projeto.nenhumSelecionado']}" 
				            	rendered="#{empty projetoServiceImpl.projetoBean.recursos}" id="message9">
				            	<f:param value="#{fn:toLowerCase(labels['projeto.recurso'])}"/>
				            </h:outputFormat>
			        </rich:tab>
			        
			        <rich:tab label="#{labels['projeto.arquivos']}" id="tabArquivos">
			        	<rich:extendedDataTable id="arquivos" var="item"
							value="#{projetoServiceImpl.projetoBean.arquivos}" 
							selectionMode="none" height="200px">
							
							<rich:column width="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState ? '90%' : '100%'}" sortable="true" sortBy="#{item.nome}" label="Nome">
								<f:facet name="header">
									Nome
								</f:facet>
								<a href="/Projeto#{item.caminho}"><h:outputText value="#{item.nome}" rendered="${projetoServiceImpl.projetoBean.detailState}"/></a>
								<h:outputText value="#{item.nome}" rendered="${projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}"/>
							</rich:column>
							
							<rich:column style="text-align: center;" label="Excluir" width="10%"
								rendered="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}">
								<f:facet name="header">
									Excluir											
								</f:facet>
								<h:graphicImage value="/img/disabled.png" style="cursor: pointer;">
									<a4j:support action="#{projetoServiceImpl.excluirArquivo}"
										event="onclick" immediate="true">
										<f:setPropertyActionListener value="#{item}" target="#{projetoServiceImpl.projetoBean.arquivoTemp}" />
									</a4j:support>
								</h:graphicImage>
							</rich:column>
			            </rich:extendedDataTable>
		            	
		            	<h:panelGroup rendered="#{projetoServiceImpl.projetoBean.createState or projetoServiceImpl.projetoBean.updateState}"
		            		id="panel4">
			            	<br />
			            	
				        	<a4j:commandButton action="#{projetoServiceImpl.mostrarPopUpUpload}" 
				        		value="Adicionar arquivo" id="btnAdicionarArquivo"/>
			        	</h:panelGroup>
			        </rich:tab>
			    </rich:tabPanel>
			    
			    <br />
			    
			    <a4j:commandButton action="#{projetoServiceImpl.confirmCreate}" value="   #{labels['confirmar']}   " 
			    	rendered="#{projetoServiceImpl.projetoBean.createState}"  id="btnConfirmCreate"/>
				<a4j:commandButton action="#{projetoServiceImpl.confirmUpdate}" value="   #{labels['confirmar']}   " 
					rendered="#{projetoServiceImpl.projetoBean.updateState}" id="btnConfirmUpdate"/>
				<rich:spacer width="7" rendered="#{not projetoServiceImpl.projetoBean.listState}" id="spacer4"/>
				<a4j:commandButton action="#{projetoServiceImpl.backToList}" value="   #{labels['cancelar']}   " 
					rendered="#{not projetoServiceImpl.projetoBean.listState}" immediate="true" id="btnBackToList"/>
			</a4j:form>
			
			<rich:modalPanel autosized="true" showWhenRendered="true" id="modalUpload" 
				rendered="#{projetoServiceImpl.projetoBean.mostrarPopUpUpload}">
				<f:facet name="header">
					<h:outputText value="Adicionar arquivo" id="message10"/>
				</f:facet>
				
				<f:facet name="controls">
		            <h:panelGroup id="panel5">
		            	<a4j:form id="closeModalForm" ajaxSubmit="true">
			                <h:graphicImage value="/img/modalClose.png" id="hideModal" style="cursor:pointer;">
			                	<a4j:support action="#{projetoServiceImpl.cancelarUpload}" event="onclick"/>
			                </h:graphicImage>
		                </a4j:form>
		            </h:panelGroup>
				</f:facet>
				
				
				<h:form id="modalForm">
					<p:messages id="mensagens" showDetail="true" 
										showSummary="false" />
					<rich:fileUpload id="upload" addControlLabel="#{labels['adicionarArquivo']}" clearAllControlLabel="Clear all" clearControlLabel="Clear"
                       		stopEntryControlLabel="#{labels['pararUpload']}" uploadControlLabel="#{labels['enviarArquivo']}" 
                       		fileUploadListener="${projetoServiceImpl.listener}" maxFilesQuantity="1"
                       		immediateUpload="true" listHeight="63px;"
                       		ajaxSingle="true" allowFlash="true"/>
					<rich:message for="upload" style="color:red;" id="messageUpload"/>
					
    				<h:panelGrid columns="2" id="panel6">
    					<h:outputLabel value="#{labels['projeto.nomeArquivo']}:" for="nomeArquivo" id="labelNomeArquivo"/>
						<h:inputText id="nomeArquivo" value="#{projetoServiceImpl.projetoBean.nomeArquivo}" 
							maxlength="100" />
						
						<h:outputLabel value="#{labels['projeto.descricaoArquivo']}:" for="descricaoArquivo" id="labelDescricaoArquivo"/>
						<h:inputTextarea id="descricaoArquivo" rows="3" cols="70" value="#{projetoServiceImpl.projetoBean.descricaoArquivo}"
							onkeyup="javascript:limitText(this, 600);" />
    				</h:panelGrid>
					
					<br />
					    	
					<a4j:commandButton action="#{projetoServiceImpl.confirmarUpload}" value="#{labels['confirmar']}" id="btnConfirmUpload"/>
					<rich:spacer width="7"/>
					<a4j:commandButton action="#{projetoServiceImpl.cancelarUpload}" value="#{labels['cancelar']}" immediate="true" id="btnCancelarUpload"/>
				</h:form>
			</rich:modalPanel>
		</ui:define>
	</ui:composition>
</html>